package com.right.health.app.ui.me.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.magic.basic.adapter.BaseAbsAdapter;
import com.right.health.app.R;
import com.right.health.app.bean.FamilyResponse;

/*
 * Created by hopeliao on 2019-09-24
 *
 */
public class FamilyAdapter extends BaseAbsAdapter<FamilyResponse.FamilyInfo> {

    private View.OnClickListener mClickListener;

    public void setOnClickListener(View.OnClickListener listener) {
        this.mClickListener = listener;
    }

    public FamilyAdapter(Context context) {
        super(context);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.family_item, null);
            viewHolder = new ViewHolder();
            viewHolder.contentImage = (ImageView) convertView.findViewById(R.id.iv_avatar);
            viewHolder.nameTv = (TextView) convertView.findViewById(R.id.tv_name);

            viewHolder.cardNumberTv = (TextView) convertView.findViewById(R.id.tv_card_number);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        FamilyResponse.FamilyInfo info = mDataSource.get(position);

        viewHolder.nameTv.setText(info.membername);
        viewHolder.cardNumberTv.setText("身份证号："+info.getShowCardNo());

//       关系(0:父亲,1:母亲,2.本人,3.妻子,4.儿子,5.女儿,6.其他,7.丈夫) (必填),
        switch (info.membership) {
            case "0":
                viewHolder.contentImage.setImageResource(R.mipmap.ic_family_type0);
                break;
            case "1":
                viewHolder.contentImage.setImageResource(R.mipmap.ic_family_type1);
                break;
            case "2":
                viewHolder.contentImage.setImageResource(R.mipmap.ic_family_type2);
                break;
            case "3":
                viewHolder.contentImage.setImageResource(R.mipmap.ic_family_type3);
                break;
            case "4":
                viewHolder.contentImage.setImageResource(R.mipmap.ic_family_type4);
                break;
            case "5":
                viewHolder.contentImage.setImageResource(R.mipmap.ic_family_type5);
                break;
            case "6":
                viewHolder.contentImage.setImageResource(R.mipmap.ic_default_avatar);
                break;
            case "7":
                viewHolder.contentImage.setImageResource(R.mipmap.ic_family_type0);
                break;
            default:
                viewHolder.contentImage.setImageResource(R.mipmap.ic_default_avatar);
                break;

        }
        return convertView;
    }

    private class ViewHolder {
        private ImageView contentImage;
        private TextView nameTv;
        private TextView cardNumberTv;
    }
}
